/* enum */
import { PageRoutesTypeEnum } from 'pub-bbx-global/pageType/dist/enum/PageRoutesEnum';
/* util */
import { openAccurateTab } from '@src/util/platform';

export function useOpenTab() {
  const fromId: any = window.frameElement?.getAttribute('id');

  // 打开新建页
  const openProjectCreateTab = (templateId: string) => {
    openAccurateTab({
      type: PageRoutesTypeEnum.PageProjectManageCreate,
      params: `templateId=${templateId}`,
      reload: true,
      fromId,
    });
  }

  // 打开编辑页
  const openProjectEditTab = ({ templateId, id }: any) => {
    openAccurateTab({
      type: PageRoutesTypeEnum.PageProjectManageEdit,
      params: `templateId=${templateId}&id=${id}&action=edit`,
      reload: true,
      fromId,
    });
  }

  // 打开详情页
  const openProjectViewTab = ({ templateId, id }: any) => {
    openAccurateTab({
      type: PageRoutesTypeEnum.PageProjectManageView,
      params: `templateId=${templateId}&id=${id}`,
      reload: true,
      fromId,
    });
  }

  return {
    openProjectCreateTab,
    openProjectEditTab,
    openProjectViewTab,
  }
}
